(function(window, angular, undefined){
	var Module = angular.module('water.apps.ws.wsclcManager.wsclcInfo.sitePollutantsManager', ['water.apps.common.stationInfo.sitePollutantsManager','water.entity.sitePollutants']);
	
	Module.controller('sitePollutantsManagerController',function($rootScope,$scope,$controller,$sitePollutantsService){
		var control = $controller("commonSitePollutantsManagerController",{$scope:$scope});
		$scope.dataPramChangedBroadCast();
		/**
		 * 监听站点列表点击事件
		 */
		if($wdp.viewValue.wwtpDetailParmWatch){
			$wdp.viewValue.wwtpDetailParmWatch();
		}
		$wdp.viewValue.wwtpDetailParmWatch = $rootScope.$watch(function(){return $wdp.viewValue.wwtpDetailParm;},function(){
			if(!$wdp.viewValue.wwtpDetailParm){
				return;
			}
			if($wdp.viewValue.wwtpDetailParm.WWTPID){
				$scope._getSitePollutantsList($wdp.viewValue.wwtpDetailParm.WWTPID);
			}
			
        },true);
		/**
		 * 提交编辑
		 */
		$scope.onSubmitEditPollClick = function(data){
			$sitePollutantsService.updateModel(data).then(function(){
				$.messager.alert("保存成功","保存成功",'info');
				 $scope._getSitePollutantsList($wdp.viewValue.wwtpDetailParm.WWTPID);
				$scope.editDialog.close();
			});
		}
		/**
		 * 删除阈值
		 */
		$scope.onDeleteAlarm = function(guid){
			$sitePollutantsService.deleteThreshold(guid).then(function(){
				$.messager.alert("删除成功","删除成功",'info');
				 $scope._getSitePollutantsList($wdp.viewValue.wwtpDetailParm.WWTPID);
			});
		}
		/**
		 * 新增阈值
		 */
		$scope.onSubmitCreateThresholdClick = function(sitePollId,mn,threshold){
			$sitePollutantsService.createThreshold(sitePollId,mn,threshold).then(function(){
				$.messager.alert("保存成功","保存成功",'info');
				$scope._getSitePollModel(sitePollId);
				 $scope._getSitePollutantsList($wdp.viewValue.wwtpDetailParm.WWTPID);
			});
		}
		/**
		 * 保存指派信息
		 */
		$scope.onSubmitEditThresholdWithChildClick = function(data){
			$sitePollutantsService.updateThresholdWithChild(data).then(function(){
				 $scope._getSitePollutantsList($wdp.viewValue.wwtpDetailParm.WWTPID);
				$.messager.alert("保存成功","保存成功",'info');
				$scope.thresholdRoleUserSetDialog.close();
			});
		}
		/**
		 * 设置标准阈值
		 */
		$scope.onSetStandardThresholdClick = function(id){
			$sitePollutantsService.setStandardThreshold(id).then(function(){
				$.messager.alert("设置成功","设置成功",'info');
				 $scope._getSitePollutantsList($wdp.viewValue.wwtpDetailParm.WWTPID);
			});
		}
		/**
		 * 获取站点列表
		 */
		 $scope._getSitePollutantsList=function (WWTP_ID){
			$sitePollutantsService.getList({WWTP_ID:WWTP_ID}).then(function(d){
				$scope.sitePolls = d;
			});
		}
	});
}(window, angular));	